<!--created by yuyupeng-->
<!--2023/11/23-->
<!-- 业务实体管理-->
<template>
  <div class="list-card-container">
    <a-card title="业务实体管理" class="general-card">
      <!-- 查询表单 -->
      <AdvancedSearch
        ref="searchRef"
        :data-source="searchItemList"
        @change="searchByParams"
      />
      <a-space style="margin-top: 5px; margin-bottom: 5px">
        <a-button type="primary" @click="showAddModal"
          ><icon-plus />新增业务实体</a-button
        >
      </a-space>
      <!-- 表格 -->
      <a-table
        v-model:selectedKeys="selectedKeys"
        row-key="id"
        column-resizable
        :columns="tbCols"
        :data="tbData"
        :pagination="pagination"
        :loading="tbLoading"
        :scroll="{ x: '100%', y: 600 }"
        :scrollbar="true"
        @page-change="onPageChange"
        @page-size-change="onPageSizeChange"
      >
        <!-- 插槽-一键复制 -->
        <template #quickCopyToolTip="{ record, column }">
          <quick-copy-tool-tip
            :show-text="record[column['dataIndex']]"
            show-btn
          />
        </template>
        <!-- 插槽-操作 -->
        <template #operation="{ record }">
          <a-space>
            <a-link type="text" @click="showEditModal(record)"> 修改 </a-link>
            <a-link type="text" @click="showEditColumnModal(record)">
              编辑实体字段
            </a-link>
            <a-popconfirm
              content="确定删除业务实体吗?"
              type="warning"
              @ok="deleteTbData(record.id)"
            >
              <a-link type="text">删除</a-link>
            </a-popconfirm>
          </a-space>
        </template>
      </a-table>
      <!-- 新增业务实体弹窗 -->
      <AdvancedFormModal
        ref="addModalRef"
        width="1200px"
        title="新增业务实体"
        :items="addModalConfig"
        :rules="advancedModalRules"
        :mask-closable="false"
        :submit-with-close="false"
        :ok-loading="okLoading"
        @ok="addModalSubmit"
      >
        <template #kbys>
          <data-source-table-select-modal
            :disabled="currentActiveTabKey !== '1'"
            :can-select-columns="true"
            @after-submit="selectedDbTableForAdd"
          />
        </template>
        <template #otherSlot>
          <a-tabs v-model:activeKey="currentActiveTabKey" type="card-gutter">
            <a-tab-pane key="1" title="实体字段">
              <BusinessDetailTable
                ref="addBusinessDetailTableRef"
                @tableNameListChange="tableNameListChangeForAdd"
              />
            </a-tab-pane>
            <a-tab-pane
              v-if="currentAddModalSelectedTableNameList.length > 1"
              key="2"
              title="主子表关联关系"
            >
              <a-alert>检测到实体字段来自多张表，请定义主子表关联关系</a-alert>
              <define-master-child-table-association
                ref="defineMasterChildTableAssociationAddRef"
                style="margin-top: 5px"
                :data-source-id="currentDataSourceConfigId"
                :table-column-list="currentAddModalSelectedTableColumnList"
                :table-name-list="currentAddModalSelectedTableNameList"
              />
            </a-tab-pane>
          </a-tabs>
        </template>
      </AdvancedFormModal>
      <!-- 修改业务实体弹窗 -->
      <AdvancedFormModal
        ref="editModalRef"
        width="600px"
        title="修改业务实体基本信息"
        :items="editModalConfig"
        :rules="advancedModalRules"
        :submit-with-close="false"
        @ok="editModalSubmit"
      />
      <!-- 编辑实体字段弹窗 -->
      <AdvancedFormModal
        ref="editColumnModalRef"
        width="1200px"
        title="编辑实体字段"
        :items="editColumnModalConfig"
        :rules="advancedModalRules"
        :mask-closable="false"
        :submit-with-close="false"
        :ok-loading="okLoading"
        @ok="editColumnModalSubmit"
      >
        <template #kbys>
          <data-source-table-select-modal
            :disabled="currentActiveTabKey !== '1'"
            :default-data-source-config-id="currentDataSourceConfigId"
            :can-select-columns="true"
            @after-submit="selectedDbTableForEdit"
          />
        </template>
        <template #otherSlot>
          <a-tabs v-model:activeKey="currentActiveTabKey" type="card-gutter">
            <a-tab-pane key="1" title="实体字段">
              <BusinessDetailTable
                ref="editBusinessDetailTableRef"
                @tableNameListChange="tableNameListChangeForEdit"
              />
            </a-tab-pane>
            <a-tab-pane
              v-if="
                currentEditColumnModalMasterChildrenTableNameList.length > 1
              "
              key="2"
              title="主子表关联关系"
            >
              <show-master-child-table-association
                ref="showMasterChildTableAssociationRef"
                style="margin-top: 5px"
              />
            </a-tab-pane>
          </a-tabs>
        </template>
      </AdvancedFormModal>
    </a-card>
  </div>
</template>

<!--新script-->
<script lang="ts" setup>
  import { Notification } from '@arco-design/web-vue';
  import { ref, onMounted, reactive, computed } from 'vue';
  import AdvancedSearch from '@/common/components/cac-components/advanced-search/index.vue';
  import AdvancedFormModal from '@/common/components/cac-components/advanced-form-modal/index.vue';
  import DataSourceTableSelectModal from '@/common/components/cac-components/datasource-table-select-modal/index.vue';
  import QuickCopyToolTip from '@/common/components/cac-components/quickcopy-tooltip/index.vue';
  import { Pagination } from '@/types/global';
  import BusinessDetailTable from '@/views/infrastructure/business-entity/components/business-detail-table.vue';
  // import SqlEditor from '@/views/infrastructure/business-entity/components/sql-editor.vue';
  import {
    BusinessColumnRecord,
    BusinessEntityAddParams,
    BusinessEntityParams,
    BusinessEntityRecord,
    MasterChildTableAssociationRecord,
  } from '@/api/infrastructure/model/businessEntityModal';
  import {
    addBusinessEntityRecord,
    deleteBusinessEntityRecord,
    getBusinessEntityAssociationRecordById,
    getBusinessEntityColumnRecordById,
    queryBusinessEntityRecordList,
    updateBusinessEntityColumnRecord,
    updateBusinessEntityRecord,
  } from '@/api/infrastructure/business-entity';
  import DefineMasterChildTableAssociation from '@/views/infrastructure/business-entity/components/define-master-child-table-association.vue';
  import ShowMasterChildTableAssociation from '@/views/infrastructure/business-entity/components/show-master-child-table-association.vue';
  import { queryDataSourceRecord } from '@/api/infrastructure/data-source-config';
  import { DataSourceRecord } from '@/api/infrastructure/model/dataSourceConfigModel';

  /**
   * data
   */
  // 表格
  const tbData = ref<BusinessEntityRecord[]>([]);
  const tbCols = [
    {
      title: '序号',
      align: 'center',
      dataIndex: 'index',
      fixed: 'left',
      width: 60,
      render: (row: any) => row.rowIndex + 1,
    },
    /* { title: '', dataIndex: 'id', fixed: 'left', ellipsis: true, align: 'center', tooltip: true },
    { title: '查看', fixed: 'left', align: 'center', width: 100, slotName: 'detail' }, */
    {
      title: '实体名称',
      dataIndex: 'alias',
      width: 150,
      align: 'center',
      tooltip: true,
    },
    {
      title: '实体编码',
      dataIndex: 'name',
      width: 150,
      ellipsis: true,
      align: 'center',
      tooltip: true,
    },
    // { title: '数据源', dataIndex: 'datasource', width: 150, ellipsis: true, align: 'center', tooltip: true },
    /* {
      title: '自定义sql',
      dataIndex: 'sql',
      width: 250,
      ellipsis: true,
      align: 'center',
    }, */
    {
      title: '创建者',
      dataIndex: 'creator',
      width: 150,
      ellipsis: true,
      align: 'center',
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      width: 150,
      ellipsis: true,
      align: 'center',
    },
    // { title: '更新者', dataIndex: 'updater', width: 150, ellipsis: true, align: 'center', tooltip: true },
    // { title: '更新时间', dataIndex: 'updateTime', width: 150, ellipsis: true, align: 'center', tooltip: true },
    // { title: '是否删除', dataIndex: 'deleted', width: 150, ellipsis: true, align: 'center', tooltip: true },
    {
      title: '操作',
      align: 'center',
      fixed: 'right',
      width: 150,
      slotName: 'operation',
    },
  ];
  const searchRef = ref<any>();
  const addModalRef = ref<any>();
  const editModalRef = ref<any>();
  const editColumnModalRef = ref<any>();
  const addBusinessDetailTableRef = ref<any>();
  const defineMasterChildTableAssociationAddRef = ref<any>();
  const showMasterChildTableAssociationRef = ref<any>();
  const editBusinessDetailTableRef = ref<any>();
  const currentAddModalSelectedTableNameList = ref<string[]>([]); // 当前新增窗口选择的实体字段来源表名数组
  const currentEditModalSelectedTableNameList = ref<string[]>([]); // 当前修改窗口选择的实体字段来源表名数组
  const currentRecord = ref<BusinessEntityRecord>(); // 当前选中行
  const currentDataSourceConfigId = ref<string>(); // 当前选择的数据源id
  const currentActiveTabKey = ref<string>('1'); // 当前选中的标签key
  // 编辑实体字段弹窗中的主子表名List
  const currentEditColumnModalMasterChildrenTableNameList = ref<string[]>([]);
  const dataSourceList = ref<DataSourceRecord[]>([]); // 数据源信息
  // const sqlEditorRef = ref<any>();
  const searchParams = ref<BusinessEntityRecord>();
  const tbLoading = ref<boolean>(false);
  const okLoading = ref<boolean>(false);
  // 勾选框
  const selectedKeys = ref([]);
  // 分页，默认第1页，每页10条
  const basePagination: Pagination = {
    current: 1,
    pageSize: 10,
    showPageSize: true,
    showTotal: true,
  };
  const pagination = reactive({
    ...basePagination,
  });
  // 搜索项配置
  const searchItemList = [
    /* { type: 'text', labelText: '', fieldName: 'id'}, */
    { type: 'text', labelText: '实体名称', fieldName: 'alias' },
    { type: 'text', labelText: '实体编码', fieldName: 'name' },
    /* { type: 'text', labelText: '数据源', fieldName: 'datasource'},
    { type: 'text', labelText: '自定义sql', fieldName: 'sql'},
    { type: 'text', labelText: '创建者', fieldName: 'creator'},
    { type: 'text', labelText: '创建时间', fieldName: 'createTime'},
    { type: 'text', labelText: '更新者', fieldName: 'updater'},
    { type: 'text', labelText: '更新时间', fieldName: 'updateTime'},
    { type: 'text', labelText: '是否删除', fieldName: 'deleted'}, */
  ];
  // computed
  // 新增弹窗配置项
  const addModalConfig = computed(() => {
    return [
      { span: 8, type: 'text', labelText: '实体名称', fieldName: 'alias' },
      { span: 8, type: 'text', labelText: '实体编码', fieldName: 'name' },
      {
        span: 8,
        type: 'other',
        labelText: '库表映射',
        fieldName: 'kbys',
      },
      {
        span: 24,
        type: 'other',
        labelText: '',
        fieldName: 'otherSlot',
      },
    ];
  });
  // 修改弹窗配置项
  const editModalConfig = computed(() => {
    return [
      {
        span: 12,
        type: 'text',
        labelText: 'id',
        fieldName: 'id',
        visible: false,
      },
      { span: 12, type: 'text', labelText: '实体名称', fieldName: 'alias' },
      { span: 12, type: 'text', labelText: '实体编码', fieldName: 'name' },
    ];
  });
  // 编辑实体字段弹窗配置项
  const editColumnModalConfig = computed(() => {
    return [
      {
        span: 24,
        type: 'text',
        labelText: 'id',
        fieldName: 'id',
        visible: false,
      },
      {
        span: 8,
        type: 'text',
        labelText: '实体名称',
        fieldName: 'alias',
        disabled: true,
      },
      {
        span: 8,
        type: 'text',
        labelText: '实体编码',
        fieldName: 'name',
        disabled: true,
      },
      {
        span: 8,
        type: 'other',
        labelText: '库表映射',
        fieldName: 'kbys',
      },
      {
        span: 24,
        type: 'other',
        labelText: '',
        fieldName: 'otherSlot',
      },
    ];
  });
  // 新增弹窗已有的业务实体字段
  const currentAddModalSelectedTableColumnList = computed(() => {
    return addBusinessDetailTableRef.value?.getFieldList();
  });
  // 弹窗表单项校验配置
  const advancedModalRules = ref({
    alias: [{ required: true, message: '请输入实体名称' }],
    name: [{ required: true, message: '请输入实体编码' }],
  });
  /**
   * func
   */
  /**
   * @method
   * @description 获取表格数据
   */
  const getTbDataByPage = async () => {
    const params: BusinessEntityParams = {
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
      ...searchParams.value,
    };
    tbLoading.value = true;
    selectedKeys.value = [];
    try {
      const { data } = await queryBusinessEntityRecordList(params);
      tbData.value = data.list;
      pagination.total = Number(data.total); // 用Number函数转一下，否则f12控制台会有警告，很不好看
    } catch (error) {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      Notification.error({
        content: `出现异常！${error}`,
        closable: true,
      });
    } finally {
      tbLoading.value = false;
    }
  };
  /**
   * @method
   * @description 按条件搜索
   */
  const searchByParams = (reqdata: any = {}) => {
    searchParams.value = reqdata;
    getTbDataByPage();
  };
  /**
   * @method
   * @description 页码发生变化触发
   */
  const onPageChange = (current: number) => {
    pagination.current = current;
    searchRef.value.handleSubmit(); // 与搜索结果保持一致
  };
  /**
   * @method
   * @description 数据条数发生变化触发
   */
  const onPageSizeChange = (pageSize: number) => {
    pagination.pageSize = pageSize;
    searchRef.value.handleSubmit(); // 与搜索结果保持一致
  };
  /**
   * @method
   * @description 删除业务实体信息
   */
  const deleteTbData = async (id: string) => {
    try {
      const res = (await deleteBusinessEntityRecord(id)) as any;
      if (res.code === 200) {
        Notification.success({
          content: '删除成功！',
        });
      } else {
        Notification.error({
          title: '删除失败！',
          content: res.message,
        });
      }
    } catch (error) {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      Notification.error({
        content: `出现异常！${error}`,
        closable: true,
      });
    } finally {
      searchRef.value.handleSubmit(); // 与搜索结果保持一致
    }
  };
  /**
   * @description 打开新增弹窗
   */
  const showAddModal = () => {
    currentAddModalSelectedTableNameList.value = []; // 重置选中的数据库表名List
    currentDataSourceConfigId.value = undefined; // 重置选择的数据源id
    currentActiveTabKey.value = '1';
    addModalRef.value.open();
  };
  /**
   * @method
   * @description 新增弹窗提交
   */
  const addModalSubmit = async (reqdata: any) => {
    try {
      const businessDetailTableDataList = JSON.parse(
        JSON.stringify(addBusinessDetailTableRef.value.getFieldList())
      );
      let flag = false;
      businessDetailTableDataList.forEach((elem: any) => {
        Object.keys(elem).forEach((item) => {
          if (item !== 'id') {
            if (elem[item].length === 0) {
              flag = true; // 发现有字段为空，不允许提交
            }
          }
        });
      });
      if (flag || businessDetailTableDataList.length === 0) {
        Notification.warning({
          content: '实体字段不能为空！',
        });
      } else {
        const isMultipleTable =
          currentAddModalSelectedTableNameList.value.length > 1; // 是否为多表模式
        let mainTableName = '';
        if (isMultipleTable) {
          // 如果选了多张表，则还需要校验一下主子表关系的定义是否完善
          const associationTableList = JSON.parse(
            JSON.stringify(
              defineMasterChildTableAssociationAddRef.value.getAssociationTableList()
            )
          );
          if (associationTableList.length === 0) {
            flag = true;
          }
          associationTableList.forEach((elem: any) => {
            Object.keys(elem).forEach((item) => {
              if (elem[item].length === 0) {
                flag = true; // 发现主子表关联关系表有字段为空，不允许提交
              }
            });
          });
          mainTableName =
            defineMasterChildTableAssociationAddRef.value.getMainTableName();
          if (flag) {
            Notification.warning({
              content: '主子表关联关系字段不能为空，请完善！',
            });
            return;
          }
        } else {
          mainTableName = currentAddModalSelectedTableNameList
            .value[0] as string;
        }
        const attrList: BusinessColumnRecord[] = []; // 实体对象属性
        businessDetailTableDataList.forEach((item: BusinessColumnRecord) => {
          attrList.push({
            columnType: item.columnType,
            comment: item.comment,
            fieldName: item.fieldName,
            jsonName: item.jsonName,
            tableName: item.tableName,
          });
        });
        let tableList: MasterChildTableAssociationRecord[] = []; // 主子表对应关系
        if (isMultipleTable) {
          tableList =
            defineMasterChildTableAssociationAddRef.value.getAssociationTableList();
        }
        const businessEntityAddParams: BusinessEntityAddParams = {
          alias: reqdata.alias,
          attrList,
          dataSourceConfigId: currentDataSourceConfigId.value,
          mainTable: mainTableName,
          tableList,
          name: reqdata.name,
        };
        okLoading.value = true;
        const res = (await addBusinessEntityRecord(
          businessEntityAddParams
        )) as any;
        okLoading.value = false;
        if (res.code === 200) {
          Notification.success({
            content: '保存成功！',
          });
          addModalRef.value.close();
        } else {
          Notification.error({
            title: '保存失败！',
            content: res.message,
          });
        }
      }
    } catch (error) {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      Notification.error({
        content: `出现异常！${error}`,
        closable: true,
      });
    } finally {
      okLoading.value = false;
      searchRef.value.handleSubmit(); // 与搜索结果保持一致
    }
  };
  /**
   * @description 打开修改业务实体弹窗
   */
  const showEditModal = (record: BusinessEntityRecord) => {
    editModalRef.value.open(record);
  };
  /**
   * @method
   * @description 修改弹窗提交
   */
  const editModalSubmit = async (reqdata: BusinessEntityRecord) => {
    try {
      const res = (await updateBusinessEntityRecord(reqdata)) as any;
      if (res.code === 200) {
        Notification.success({
          content: '修改成功！',
        });
        editModalRef.value.close();
      } else {
        Notification.error({
          title: '保存失败！',
          content: res.message,
        });
      }
    } catch (error) {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      Notification.error({
        content: `出现异常！${error}`,
        closable: true,
      });
    } finally {
      searchRef.value.handleSubmit(); // 与搜索结果保持一致
    }
  };
  /**
   * @description 打开编辑实体字段弹窗
   */
  const showEditColumnModal = async (record: BusinessEntityRecord) => {
    currentActiveTabKey.value = '1';
    currentDataSourceConfigId.value = record.dataSourceConfigId; // 设置选择的数据源id
    currentRecord.value = record;
    editColumnModalRef.value.open(record);
    const dataSourceConfigName = dataSourceList.value.filter(
      (e) => e.id === record.dataSourceConfigId
    )[0].name;
    const { data } = await getBusinessEntityColumnRecordById(
      // 获取实体字段
      record.id as string
    );
    data.forEach((item: any) => {
      item.dataSourceName = dataSourceConfigName;
    });
    setTimeout(() => {
      editBusinessDetailTableRef.value.clearFieldList();
      editBusinessDetailTableRef.value.addTbDataBatch(data);
    }, 500);
    const associationResult = await getBusinessEntityAssociationRecordById(
      // 获取关联关系
      record.id as string
    );
    if (associationResult.data.length > 0) {
      // 如果associationResult.data有数据，则说明是主子表结构
      const tableNameSet = new Set();
      associationResult.data.forEach((item: any) => {
        tableNameSet.add(item.curTable);
        tableNameSet.add(item.joinTable);
      });
      currentEditColumnModalMasterChildrenTableNameList.value = [
        ...tableNameSet,
      ] as string[];
    } else {
      // associationResult.data没数据，直接把data.tableName放进去
      currentEditColumnModalMasterChildrenTableNameList.value = [
        data[0].tableName,
      ];
    }
    setTimeout(() => {
      showMasterChildTableAssociationRef.value.clearFieldList();
      showMasterChildTableAssociationRef.value.addTbDataBatch(
        associationResult.data
      );
    }, 500);
  };
  /**
   * @description 修改实体字段弹窗提交
   * @param reqdata
   */
  const editColumnModalSubmit = async (reqdata: BusinessEntityRecord) => {
    try {
      const businessDetailTableDataList = JSON.parse(
        JSON.stringify(editBusinessDetailTableRef.value.getFieldList())
      );
      let flag = false;
      businessDetailTableDataList.forEach((elem: any) => {
        Object.keys(elem).forEach((item) => {
          if (item !== 'id') {
            if (elem[item].length === 0) {
              flag = true; // 发现有字段为空，不允许提交
            }
          }
        });
      });
      if (flag || businessDetailTableDataList.length === 0) {
        Notification.warning({
          content: '实体字段不能为空！',
        });
      } else {
        const attrList: BusinessColumnRecord[] = [];
        businessDetailTableDataList.forEach((item: BusinessColumnRecord) => {
          attrList.push({
            columnType: item.columnType,
            comment: item.comment,
            fieldName: item.fieldName,
            jsonName: item.jsonName,
            tableName: item.tableName,
          });
        });
        okLoading.value = true;
        const res = (await updateBusinessEntityColumnRecord(
          reqdata.id as string,
          attrList
        )) as any;
        okLoading.value = false;
        if (res.code === 200) {
          Notification.success({
            content: '修改成功！',
          });
          editColumnModalRef.value.close();
        } else {
          Notification.error({
            title: '修改失败！',
            content: res.message,
          });
        }
      }
    } catch (error) {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      Notification.error({
        content: `出现异常！${error}`,
        closable: true,
      });
    } finally {
      okLoading.value = false;
      searchRef.value.handleSubmit(); // 与搜索结果保持一致
    }
  };
  /**
   * @param str 需要转驼峰的下划线字符串
   * @returns 字符串驼峰
   */
  const underlineToHump = (str: string) => {
    if (!str) return '';
    return str.replace(/_(\w)/g, (_, letter: string) => {
      return letter.toUpperCase();
    });
  };
  /**
   * @description 将数据库表列字段转换成表格组件能识别的格式
   * @param tableColumnsList
   * @param tableName
   * @param dataSourceConfigName
   */
  const translateTbColumnToTbDataFormatter = (
    tableColumnsList: any[],
    tableName: string,
    dataSourceConfigName: string
  ) => {
    const newData = [] as any[];
    tableColumnsList.forEach((item) => {
      newData.push({
        id: new Date().getTime() + item.name,
        dataSourceName: dataSourceConfigName, // 数据源名称
        fieldName: item.name, // 数据库字段列名
        jsonName: underlineToHump(item.name), // Json属性
        tableName, // 所属表名
        columnType: item.columnType, // Json类型
        comment: item.comment, // 备注
      });
    });
    return newData;
  };
  /**
   * @description 新增实体对话框选择数据库表后触发
   * @param tbDataInfo
   */
  const selectedDbTableForAdd = (tbDataInfo: any) => {
    if (currentDataSourceConfigId.value !== undefined) {
      // 如果currentDataSourceConfigId已经存在，说明已经选过一次数据库表了
      if (currentDataSourceConfigId.value !== tbDataInfo.dataSourceConfigId) {
        Notification.warning({
          content: '暂不支持同一实体导入不同数据源的数据库表字段！',
        });
        return;
      }
    }
    if (tbDataInfo.tableColumnsList.length > 0) {
      const newTbData = translateTbColumnToTbDataFormatter(
        tbDataInfo.tableColumnsList,
        tbDataInfo.tableName,
        tbDataInfo.dataSourceConfigName
      );
      currentDataSourceConfigId.value = tbDataInfo.dataSourceConfigId;
      addBusinessDetailTableRef.value.addTbDataBatch(newTbData);
    }
  };
  /**
   * @description 新增对话框实体字段来源表名List发生变化触发
   * @param tableNameList
   */
  const tableNameListChangeForAdd = (tableNameList: any[]) => {
    currentAddModalSelectedTableNameList.value = tableNameList;
    if (tableNameList.length === 0) {
      // 在新增实体的时候，如果把实体字段删完了，那么currentDataSourceConfigId也需要重置为undefined
      currentDataSourceConfigId.value = undefined;
    }
  };
  /**
   * @description 修改对话框实体字段来源表名List发生变化触发
   * @param tableNameList
   */
  const tableNameListChangeForEdit = (tableNameList: any[]) => {
    currentEditModalSelectedTableNameList.value = tableNameList;
  };
  /**
   * @description 修改实体对话框选择数据库表后触发
   * @param tbDataInfo
   */
  const selectedDbTableForEdit = (tbDataInfo: any) => {
    if (currentDataSourceConfigId.value !== undefined) {
      // 如果currentDataSourceConfigId已经存在，说明已经选过一次数据库表了
      if (currentDataSourceConfigId.value !== tbDataInfo.dataSourceConfigId) {
        Notification.warning({
          content: '暂不支持同一实体导入不同数据源的数据库表字段！',
        });
        return;
      }
    }
    if (
      currentEditColumnModalMasterChildrenTableNameList.value.filter(
        (e) => e === tbDataInfo.tableName
      ).length === 0
    ) {
      // 如果选了其他表的字段，则不允许添加，因为暂时不考虑编辑实体字段的时候新增表，因为那样要重新维护关联关系字段，不好实现
      Notification.warning({
        content: `只能选择${currentEditColumnModalMasterChildrenTableNameList.value.toString()}数据库表的字段！`,
      });
      return;
    }
    if (tbDataInfo.tableColumnsList.length > 0) {
      const newTbData = translateTbColumnToTbDataFormatter(
        tbDataInfo.tableColumnsList,
        tbDataInfo.tableName,
        tbDataInfo.dataSourceConfigName
      );
      editBusinessDetailTableRef.value.addTbDataBatch(newTbData);
    }
  };
  /**
   * @description 获取所有的数据源信息
   */
  const listDataSource = async () => {
    const { data } = await queryDataSourceRecord();
    dataSourceList.value = data;
  };
  /**
   * onMounted
   */
  onMounted(() => {
    getTbDataByPage();
    listDataSource();
  });
</script>

<style lang="less" scoped>
  .list-card-container {
    padding: 20px;
    // background-color: var(--color-bg-1);
    border-radius: var(--border-radius-default);
  }
</style>
